//
//  BYLeftTableViewController.m
//  仿QQ抽屉效果
//
//  Created by Sean Sebastian on 6/7/16.
//  Copyright © 2016 Sean Sebastian. All rights reserved.
//

#import "BYLeftTableViewController.h"
#import "BYDrawerViewController.h"

@interface BYLeftTableViewController ()

@end

@implementation BYLeftTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background"]];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 200)];
    v.backgroundColor = [UIColor whiteColor];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeContactAdd];
    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    btn.frame = CGRectMake(50, 50, 50, 50);
    [v addSubview:btn];
    self.tableView.tableHeaderView = v;
    
}

- (void)btnClick
{
    UIViewController *vc = [[UIViewController alloc] init];
    vc.title = @"新的控制器！";
    vc.view.backgroundColor = [UIColor blueColor];
    UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
    
    // 这里的target应该是抽屉控制器，回调方法是backHome方法
    vc.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleDone target:[BYDrawerViewController sharedDrawerViewController] action:@selector(backHome)];
    
    [[BYDrawerViewController sharedDrawerViewController] switchViewController:nvc];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    }
    cell.backgroundColor = [UIColor clearColor];
    cell.textLabel.text = [NSString stringWithFormat:@"%ld-%ld" , indexPath.section , indexPath.row];
    cell.textLabel.textColor = [UIColor whiteColor];
    return cell;
}

@end
